<?php



namespace App\Http\Controllers\Api\Dynamic;


use App\Http\Controllers\Api\BasicController;
use App\Http\Controllers\Api\User\MarketLevel;
use App\Models\Dynamic\Lists;
use App\Models\Dynamic\Tag;
use App\Models\SiteCode;
use App\Models\User;
use App\Models\UserInfo;
use App\Services\Sms;
use GatewayWorker\Lib\Gateway;
use Jiannei\Response\Laravel\Support\Facades\Response;

class TagController extends BasicController
{


    /**
     * @api {post} /dynamic/tag/add  添加标签
     * @apiHeader {String} Authorization='Bearer '
     */
    public function add()
    {
        $params = $this->data(['name']);
        $data=[];
        foreach ($params['name'] as $name){
            $data[]=['user_id'=>$this->uid(),'name'=>$name];
        }
        $result = Tag::insert($data);
        return Response::success($result);
    }

    /**
     * @api {post} /dynamic/tag/del  删除
     * @apiHeader {String} Authorization='Bearer '
     */
    public function del()
    {
        $where=['id'=>$this->request->input('id'),'user_id'=>$this->uid()];
        $result = Tag::where($where)->delete();
        return Response::success($result);
    }

    public function list(){
        $where=[0,$this->uid()];
        $result= Tag::whereIn('user_id',$where)->get();
        return Response::success($result);
    }
}
